package com.stm.web.controller.basicData;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stm.basicData.domain.KfToolsUseUnit;
import com.stm.basicData.service.KfToolsUseUnitService;
import com.stm.common.annotation.Log;
import com.stm.common.core.controller.BaseController;
import com.stm.common.core.domain.AjaxResult;
import com.stm.common.core.page.TableDataInfo;
import com.stm.common.enums.BusinessType;
import com.stm.framework.util.ShiroUtils;

/**
 * 使用单位
 * 
 * @author wyc
 * @date 2019-04-08
 */
@Controller
@RequestMapping("/basicData/kfToolsUse")
public class ToolsUseController extends BaseController
{
    private String prefix = "basicData/kfToolsUse";
	
	@Autowired
	private KfToolsUseUnitService kfToolsUseUnitService;

	@RequiresPermissions("basicData:kfToolsUse:view")
	@GetMapping()
	public String kfToolsUse(ModelMap mmap)
	{
		
		mmap.put("user", ShiroUtils.getSysUser());
	    return prefix + "/kfToolsUse";
	}
	
	/**
	 * 查询使用单位列表
	 */
	@RequiresPermissions("basicData:kfToolsUse:view")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(KfToolsUseUnit kfToolsUseUnit)
	{
		startPage();
        List<KfToolsUseUnit> list = kfToolsUseUnitService.selectKfToolsUseUnitList(kfToolsUseUnit);
		return getDataTable(list);
	}
	
	/**
	 * 新增使用单位
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/kfToolsUse_add";
	}
	
	/**
	 * 新增保存使用单位
	 */
	@RequiresPermissions("basicData:kfToolsUse:add")
	@Log(title = "使用单位", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(KfToolsUseUnit kfToolsUseUnit)
	{
		kfToolsUseUnit.setDprtcode(ShiroUtils.getSysUser().getDeptId());
		kfToolsUseUnit.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(kfToolsUseUnitService.insertKfToolsUseUnit(kfToolsUseUnit));
	}

	/**
	 * 修改使用单位
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		KfToolsUseUnit kfToolsUseUnit = kfToolsUseUnitService.selectKfToolsUseUnitById(id);
		mmap.put("kfToolsUseUnit", kfToolsUseUnit);
	    return prefix + "/kfToolsUse_edit";
	}
	
	/**
	 * 修改保存使用单位
	 */
	@RequiresPermissions("basicData:kfToolsUse:edit")
	@Log(title = "使用单位", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(KfToolsUseUnit kfToolsUseUnit)
	{
		kfToolsUseUnit.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(kfToolsUseUnitService.updateKfToolsUseUnit(kfToolsUseUnit));
	}
	
	/**
	 * 删除使用单位
	 */
	@RequiresPermissions("basicData:kfToolsUse:remove")
	@Log(title = "使用单位", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(kfToolsUseUnitService.deleteKfToolsUseUnitByIds(ids));
	}
	
	 /**
     * @param user
     * @return
     * @Description 初始化使用单位下拉框数据
     * @CreateTime 2019年4月8日 上午11:22:58
     * @CreateBy 林龙
     */
    @PostMapping("/initUse")
    @ResponseBody
    public List<KfToolsUseUnit> initUse(KfToolsUseUnit kfToolsUseUnit) {
        return kfToolsUseUnitService.selectKfToolsUseUnitList(kfToolsUseUnit);
    }
	
}
